package com.chen.back.thread;

import java.util.concurrent.*;

/**
 * @author chen
 * @date @{DATE} -10:40
 **/
public class ThreadTest {
  public static   ExecutorService pool = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {

//        没有返回值
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {

            System.out.println(Thread.currentThread().getId());
        }, pool);

        //有返回值
        CompletableFuture<Integer> supplyAsync = CompletableFuture.supplyAsync(() -> {

            System.out.println(Thread.currentThread().getId());
            int i = 10 / 2;
            return i;
        }, pool);

        System.out.println(supplyAsync.get());

        //使用同一个线程,感知异常
        CompletableFuture<Integer> supply = CompletableFuture.supplyAsync(() -> {

            System.out.println(Thread.currentThread().getId());
            int i = 10 / 2;
return i;
        }, pool).whenCompleteAsync((u,t)->{

            System.out.println("上一次的结果是："+u);
            System.out.println("议常是："+t);

        },pool);
    }
}
